package demo.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 *    
 * 控制层
 *
 * @desc:
 * @author: li.peng02
 * @date: 2019/3/13
 * @version: v1.0 
 */
@RestController
public class RibbonController {

    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping("/testHystrix/{id}")
    @HystrixCommand(fallbackMethod = "getError")
    public String test01(@PathVariable String id) {
        return restTemplate.getForObject("http://spring-cloud-producer/feign/get/" + id, java.lang.String.class);
    }

    public String getError(String id) {
        System.out.println(Thread.currentThread().getName() + ":getError");
        return "超时错误,使用断路器返回" + id;
    }
}
